<template>
  <div>
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <span>筛选查询</span>
      </div>
      <div class="text item">
        <el-form
          :model="queryParams"
          ref="queryForm"
          :inline="true"
        >
          <el-form-item label="" prop="jiguanProvince">
            <el-select
              v-model="queryParams.jiguanProvince"
              placeholder="所在省份"
              clearable
              size="small"
              @change="changeProvince"
            >
              <el-option
                v-for="(item, index) in provinceList"
                :key="index"
                :label="item.provinceName"
                :value="item.provinceId"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="" prop="jiguanCity">
            <el-select
              v-model="queryParams.jiguanCity"
              placeholder="所在城市"
              clearable
              size="small"
            >
              <el-option
                v-for="(item, index) in cityList"
                :key="index"
                :label="item.name"
                :value="item.cityId"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="" prop="name">
            <el-input
              v-model="queryParams.name"
              placeholder="请输入姓名"
              clearable
              size="small"
            />
          </el-form-item>

          <el-form-item>
            <el-button
              type="primary"
              icon="el-icon-search"
              size="mini"
              @click="handleQuery"
            >搜索
            </el-button
            >
            <el-button
              type="primary"
              icon="el-icon-refresh"
              size="mini"
              @click="resetQuery"
            >重置
            </el-button
            >
          </el-form-item>
        </el-form>
      </div>
    </el-card>

    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <span>数据列表</span>
      </div>
      <div class="text item">
        <el-table v-loading="loading" :data="tableList">
          <el-table-column label="所在省份" align="center" prop="jiguanProvince"/>
          <el-table-column label="所在城市" align="center" prop="jiguanCity"/>
          <el-table-column label="所在中学" align="center" prop="school"/>
          <el-table-column label="姓名" align="center" prop="name"/>
          <el-table-column label="联系电话" align="center" prop="phone"/>
          <el-table-column label="提交资料时间" align="center" prop="submitTime"/>
          <el-table-column label="邀请码名称" align="center" prop="invitationName"/>
          <el-table-column label="邀请码ID" align="center" prop="invitationCode"/>
          <el-table-column v-if="typeFu==0" label="当前状态" align="center" prop="status"/>
          <el-table-column
            label="操作"
            align="center"
            class-name="small-padding fixed-width"
          >
            <template slot-scope="scope">
              <el-button
                v-if="typeFu==0"
                size="mini"
                type="text"
                @click="handleCheck(scope.row)"
                v-hasPermi="['campSystem:campManager:check:check']"
              >审核</el-button>
              <el-button
                v-if="typeFu==1||typeFu==2"
                size="mini"
                type="text"
                @click="handleView(scope.row)"
              >查看</el-button>
            </template>
          </el-table-column>
          <el-table-column v-if="typeFu==2" label="不通过原因" align="center" prop="examineReason"/>
        </el-table>
      </div>
      <pagination
        v-show="total > 0"
        :total="total"
        :page.sync="queryParams.page"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </el-card>
    <!--审核报名资料弹框-->
    <check-form
      :dialogVisibleFu="dialogVisibleFu"
      :phoneFu="phoneFu"
      :campsiteIdFu="idFu"
      :typeFu="typeFu"
      titleFu="审核报名资料"
      @closeDialog="closeDialog"
    ></check-form>
    <!--审核通过确认弹框-->
    <pass-dialog
      :passDialogVisibleFu="passDialogVisibleFu"
      :idCardFu="idCardFu"
      :campsiteIdFu="idFu"
      @closePassDialog="closePassDialog"
    ></pass-dialog>
    <!--审核不通过确认弹框-->
    <no-pass-dialog
      :noPassDialogVisibleFu="noPassDialogVisibleFu"
      :campsiteIdFu="idFu"
      :idCardFu="idCardFu"
      @closeNoPassDialog="closeNoPassDialog"
    ></no-pass-dialog>
  </div>
</template>

<script>
  import { GetProvinceList, GetCityList, GetDaiCheckList,GetYesCheckList, GetNoCheckList } from "@/api/campSystem/campOper";
  import CheckForm from "@/components/CampSystem/CampOper/Check/CheckForm";
  import PassDialog from "@/components/CampSystem/CampOper/Check/PassDialog";
  import NoPassDialog from "@/components/CampSystem/CampOper/Check/NoPassDialog";
  export default {
    name: "WaitCheck",
    props: {
      typeFu: [Number,String],
      idFu: [String,Number]
    },
    components: {
      CheckForm,
      PassDialog,
      NoPassDialog
    },
    data() {
      return {
        loading: false,// 表格加载loading
        queryParams: {
          page: 1,
          pageSize: 10,
          campsiteId: null,
          jiguanProvince: null,
          jiguanCity: null,
          name: null
        },
        total: 0,// 数据总条数
        tableList: [], // 表格数据列表
        statusOptions: [], // 营地报名状态列表
        provinceList: [],// 省份列表
        cityList: [],// 城市列表
        phoneFu: '',// 当前审核弹框的phone
        idCardFu: '',// 当前审核弹框的idCard
        dialogVisibleFu: false, // 控制审核报名资料弹框显示与隐藏
        passDialogVisibleFu: false, // 控制审核通过确认弹框显示与隐藏
        noPassDialogVisibleFu: false, // 控制审核不通过弹框显示与隐藏
      };
    },
    created() {
      this.queryParams.campsiteId = this.idFu;
      this.getDicts("camp_signup_status").then(response => {
        this.statusOptions = response.data;
      });
      this.getProvince();
      this.getList();
    },
    methods: {
      // 关闭审核不通过确认弹框，子组件触发
      closeNoPassDialog(val, type){
        this.noPassDialogVisibleFu = val;
        if(type){
          this.getList();
        }
      },
      // 关闭审核通过确认弹框，子组件触发
      closePassDialog(val, type){
        this.passDialogVisibleFu = val;
        if(type){
          this.getList();
        }
      },
      // 关闭审核报名资料弹框，子组件触发
      closeDialog(val, type, data){
        console.log(val, type, data)
        this.dialogVisibleFu = val;
        if(type==1){
          this.idCardFu = data.idCard;
          this.passDialogVisibleFu = true;
        }else if(type==2){
          this.idCardFu = data.idCard;
          this.noPassDialogVisibleFu = true;
        }
      },
      // 查看按钮
      handleView(data){
        this.phoneFu = data.phone;
        this.dialogVisibleFu = true;
      },
      // 审核按钮
      handleCheck(data){
        this.phoneFu = data.phone;
        this.dialogVisibleFu = true;
      },
      // 重置按钮
      resetQuery() {
        this.$refs['queryForm'].resetFields();
        this.handleQuery();
      },
      // 搜索按钮
      handleQuery() {
        this.queryParams.page = 1;
        this.queryParams.pageSize = 10;
        this.getList();
      },
      // 获取列表
      getList() {
        this.loading = true;
        if(this.typeFu == 0){
          GetDaiCheckList(this.queryParams)
            .then(response => {
              console.log(response);
              if (response.code != 200) {
                this.loading = false;
                return this.msgError(response.msg);
              }
              this.tableList = response.data;
              this.total = response.total;
              this.loading = false;
            })
            .catch(error => {
              console.log(error);
              this.loading = false;
            });
        }else if(this.typeFu==1){
          GetYesCheckList(this.queryParams)
            .then(response => {
              console.log(response);
              if (response.code != 200) {
                this.loading = false;
                return this.msgError(response.msg);
              }
              this.tableList = response.data;
              this.total = response.total;
              this.loading = false;
            })
            .catch(error => {
              console.log(error);
              this.loading = false;
            });
        }else{
          GetNoCheckList(this.queryParams)
            .then(response => {
              console.log(response);
              if (response.code != 200) {
                this.loading = false;
                return this.msgError(response.msg);
              }
              this.tableList = response.data;
              this.total = response.total;
              this.loading = false;
            })
            .catch(error => {
              console.log(error);
              this.loading = false;
            });
        }

      },
      // 字典状态字典翻译
      statusFormat(row, column) {
        return this.selectDictLabel(this.statusOptions, row.status);
      },
      // 改变省份，获取城市列表
      changeProvince(value) {
        GetCityList(value+'').then((res) => {
          if(res.code != 200){
            return this.$message.error(res.msg);
          }
          this.cityList = res.data;
          this.queryParams.jiguanCity = null;
          console.log(res)
        }).catch(err=>{
          console.log(err);
        });
      },
      // 获取省份列表
      getProvince(){
        GetProvinceList()
          .then(response => {
            this.provinceList = response;
          })
      }
    },
    watch: {
      typeFu(val){
        this.getList();
      },
      idFu(val){
        this.queryParams.campsiteId = val;
        this.getList();
      },
    }
  }
</script>

<style lang="scss">
  @import "@/assets/styles/card.scss";
</style>


